//
//  OrderDetailesVC.m
//  YaoHeAPP
//
//  Created by mac on 15/12/22.
//  Copyright © 2015年 mac. All rights reserved.
//

#import "OrderDetailesVC.h"
#import "Controller.h"
#import "OrderDatailClass.h"
#import "UIImageView+WebCache.h"
#import "Masonry.h"
#import "AccurateVC.h"
#import "CommentsVC.h"
#import "CWStarRateView.h"
#import "Define.h"
#import "ProvinceAndCity.h"
#import "SVPullToRefresh.h"
#import "BigimageView.h"
#define Color153  [UIColor colorWithRed:102.f/255.f green:102.f/255.f blue:102.f/255.f alpha:1]


#import "QClistViewController.h"
#import "QuxiaoQCViewController.h"

#import "UIView+HY.h"

//#define Color153  [UIColor colorWithRed:80.f/255.f green:80.f/255.f blue:80.f/255.f alpha:1]


@interface OrderDetailesVC ()<UIAlertViewDelegate>
{
    NSInteger width;
    NSInteger height;
    OrderDatailClass*detailClass;//存放数据的对象
    NSArray*arrayTitle;//数组放置标签标题
    BOOL juan_cai;//卷材
    BOOL ban__cai;//板材
    BOOL guan_cai;//管材
    BOOL xing_cai;//型材
    BOOL lv_cai;  //铝材
    
    
    NSInteger CellH;
    
    NSInteger   beizhuW;
    NSInteger   beizhuH;
    
   }
@end

@implementation OrderDetailesVC

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    [MobClick endLogPageView:@"OrderDetailesVC"];
    
    [[self rdv_tabBarController] setTabBarHidden:NO animated:YES];
}


-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    [MobClick beginLogPageView:@"OrderDetailesVC"];
    
    [[self rdv_tabBarController] setTabBarHidden:YES animated:YES];

    
    [self viewDidLoad];
    //[_tableView reloadData];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    //self.navigationItem.title=@"订单详情";

    width=self.view.frame.size.width;
    height=self.view.frame.size.height;

    self.view.backgroundColor=bgVCcolor;
    //加一个导航条
    UIView*navcBar=[[UIView alloc]init];
    navcBar.backgroundColor=[UIColor colorWithRed:90.f/255.f green:191.f/255.f blue:219.f/255.f alpha:1];
    [self.view addSubview:navcBar];
    [self.view bringSubviewToFront:navcBar];
    [navcBar mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(0);   make.left.offset(0);
        make.height.offset(kNavigationBarHeight);  make.right.offset(0);
    }];
//
    //导航条标题
    UILabel*titleLabel=[[UILabel alloc]init];
    titleLabel.text=@"订单详情";
    titleLabel.font=Font(17);
    titleLabel.textAlignment=NSTextAlignmentCenter;
    titleLabel.textColor=[UIColor whiteColor];
    [navcBar addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(25);
        make.left.offset(width/2-70);
        make.width.offset(150);
        make.height.offset(30);
    }];
    //
    UIButton*leftButton=[UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setBackgroundImage:[UIImage imageNamed:@"return"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    [navcBar addSubview:leftButton];
    [leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(6);
        make.width.offset(24);
        make.height.offset(22);
        make.bottom.offset(-12);
    }];

    NSDictionary*dic=@{@"ORDER_ID":self.orderID};
    
    [Controller requestWithURL:@"AppSaleOrder/PostQuerySaleOrderDetail?from=app" jsondic:dic finishBlock:^(ClassData *classData) {
        NSDictionary*dic=classData.data;
        OrderDatailClass*classD=[[OrderDatailClass alloc]initWithDid:dic];
        detailClass=classD;
        
        juan_cai =[detailClass.categoryName isEqualToString:@"卷材"];
        ban__cai =[detailClass.categoryName isEqualToString:@"板材"];
        guan_cai =[detailClass.categoryName isEqualToString:@"管材"];
        xing_cai =[detailClass.categoryName isEqualToString:@"型材"];
        lv_cai=[detailClass.categoryName isEqualToString:@"铝材"];
        if (detailClass.logisticsScore==nil||detailClass.serviceScore==nil||detailClass. productScore==nil) {
        }
        
        //要显示的内容
        NSString*categoryName=detailClass.varietyName;//品名
        NSString*material=detailClass.materialName;//材质
        if (lv_cai==YES) {
            material=detailClass.tradeMark;
        }
        NSString*supface=detailClass.surfaceName;//表面
        if (material.length==0){
            material=@"无";
        }
        if(supface.length==0){
            supface=@"无";
        }
        NSString*materialSupface=[NSString stringWithFormat:@"%@/%@",material,supface];//材质和表面
        NSString*speccode=[NSString stringWithFormat:@"%@",detailClass.specCode];//规格
        NSString*tolerance=[NSString stringWithFormat:@"%@",detailClass.tolerance];//公差
        if (lv_cai==YES) {
            tolerance=[NSString stringWithFormat:@"%@",detailClass.nationalStandard];
        }
        NSString*weight=@"";
        NSString*quantity=@"";
        if (detailClass.weight.length==0){
            weight=@"无";
        }
        if (detailClass.weight.length>0) {
            weight=[NSString stringWithFormat:@"%@吨",detailClass.weight];
        }
        
        if (detailClass.quantity.length==0){
            quantity=@"无";
        }
        if (detailClass.quantity.length>0) {
            if (xing_cai==YES||juan_cai==YES){
                quantity=[NSString stringWithFormat:@"%@个",detailClass.quantity];
            }
            if (ban__cai==YES||lv_cai==YES){
                quantity=[NSString stringWithFormat:@"%@张",detailClass.quantity];
            }
            if (guan_cai==YES) {
                quantity=[NSString stringWithFormat:@"%@支",detailClass.quantity];
            }
        }
        NSString*weightQuantity=[NSString stringWithFormat:@"%@/%@",weight,quantity];//重量，数量

        //生产商
        NSString*manufacturer=detailClass.manufacturerName;
        if (manufacturer.length==0) {
            manufacturer=@"无";}
        NSString*shengCityManufacturer=[NSString stringWithFormat:@"%@%@/%@",[ProvinceAndCity inputShengID:detailClass.supplyProvinceID],[ProvinceAndCity inputCityID: detailClass.supplyCityID],manufacturer];//省市、生产商
        
        
        NSInteger isInvoice=[detailClass.isNeedInvoice integerValue];//将string转为integer类型
        NSString*is_nned_invoice=[NSString string];//是否需要发票
        if (isInvoice==0)
        {
            is_nned_invoice=@"不需要";
        }
        if (isInvoice==1)
        {
            is_nned_invoice=@"需要";
        }
        NSString*remark=[NSString stringWithFormat:@"%@",detailClass.purchaseRemark];//备注信息
        //在数组中添加
        _detailArray=[[NSMutableArray alloc]initWithObjects:@"",categoryName,materialSupface,speccode,tolerance,weightQuantity,shengCityManufacturer,is_nned_invoice,remark,@"",@"",nil];
    
        //创建表格
        _tableView=[[UITableView alloc]initWithFrame:CGRectMake(0, kNavigationBarHeight, width, height-kNavigationBarHeight-60) style:UITableViewStyleGrouped];
        _tableView.delegate=self;
        _tableView.dataSource=self;
        _tableView.separatorStyle=UITableViewCellSeparatorStyleNone;
        [self.view addSubview:_tableView];
        
        //背景
        UIView*backView=[[UIView alloc]init];
        backView.backgroundColor=[UIColor whiteColor];
        [self.view addSubview:backView];
        [backView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(-1);
            make.right.offset(1);
            make.bottom.offset(1);
            make.height.offset(60);
        }];

        
        //电话找货按钮
        UIButton*phoneBtnz=[UIButton buttonWithType:UIButtonTypeCustom];
        phoneBtnz.layer.masksToBounds=YES;
        phoneBtnz.layer.cornerRadius=18;
        [phoneBtnz setBackgroundImage:[UIImage imageNamed:@"Phone_call_for_goods"] forState:UIControlStateNormal];
        [phoneBtnz setBackgroundImage:[UIImage imageNamed:@"phoneFindHF"] forState:UIControlStateHighlighted];
        [phoneBtnz addTarget:self action:@selector(callPhoneKefu) forControlEvents:UIControlEventTouchUpInside];
        [backView addSubview:phoneBtnz];
        [phoneBtnz mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.offset(30);
            make.height.offset(36);
            make.width.offset(36);
            make.bottom.offset(-13);
        }];

        
        //重新采购
        UIButton* again_Btn=[UIButton buttonWithType:UIButtonTypeCustom];
        again_Btn.layer.masksToBounds=YES;
        again_Btn.layer.cornerRadius=18;
        again_Btn.titleLabel.font=font15;
        again_Btn.backgroundColor=[UIColor colorWithRed:55.f/255.f green:177.f/255.f blue:249.f/255.f alpha:1];
        [again_Btn addTarget:self action:@selector(again_Btn) forControlEvents:UIControlEventTouchUpInside];
        [again_Btn setTitle:@"重新采购" forState:UIControlStateNormal];
        [again_Btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        [backView addSubview:again_Btn];
        [again_Btn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(phoneBtnz.mas_right).offset(15);
            make.width.offset((width-86)/2-15);
            make.height.offset(36);
            make.bottom.offset(-13);
        }];
    
        
        //评论按钮
        UIButton*commentsBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        commentsBtn.layer.masksToBounds=YES;
        commentsBtn.layer.cornerRadius=18;
        commentsBtn.titleLabel.font=font15;
        commentsBtn.layer.borderColor=[UIColor colorWithRed:55.f/255.f green:177.f/255.f blue:249.f/255.f alpha:1].CGColor;
        commentsBtn.layer.borderWidth=0.5;
        if (detailClass.logisticsScore==nil||detailClass.serviceScore==nil||detailClass.productScore==nil) {
            [commentsBtn addTarget:self action:@selector(comments) forControlEvents:UIControlEventTouchUpInside];
            [commentsBtn setTitle:@"评论" forState:UIControlStateNormal];
        }
        else{
            [commentsBtn setTitle:@"已评论" forState:UIControlStateNormal];
        }
        [commentsBtn setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
        [backView addSubview:commentsBtn];
        [commentsBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(again_Btn.mas_right).offset(15);
            make.width.offset((width-86)/2-15);
            make.height.offset(36);
            make.bottom.offset(-13);

        }];

        __block OrderDetailesVC*vc = self;
        [_tableView addPullToRefreshWithActionHandler:^{
            //刷新数据的操作
            [vc viewDidLoad];
        }];


    }];
     // Do any additional setup after loading the view.
}

//返回多少分区
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 3;
}

//返回每个分区的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section==0) {
        return 1;
    }
    if (section==1) {
        return 2;
    }
    return 11;
}

//返回每行单元格的高度
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        if ([detailClass.isNeedTesting integerValue]==1){
            beizhuW=self.view.frame.size.width-100-70-2;
            beizhuH=[self stringRect:detailClass.quoteRemark uiWidth:beizhuW font:font15];
            CellH=[self stringRect:detailClass.quoteRemark uiWidth:beizhuW font:font15]+42;
          return  [self stringRect:detailClass.quoteRemark uiWidth:beizhuW font:font15]+42;
        }
        else{
            beizhuW=self.view.frame.size.width-70-2;
            beizhuH=[self stringRect:detailClass.quoteRemark uiWidth:beizhuW font:font15];
            CellH=[self stringRect:detailClass.quoteRemark uiWidth:beizhuW font:font15]+42;
          return  [self stringRect:detailClass.quoteRemark uiWidth:beizhuW font:font15]+42;
        }
    }
    if (indexPath.section==1) {
        if (indexPath.row==0) {
            return 25;
        }
        if (indexPath.row==1) {
            return 60;
        }
    }
    if (indexPath.row==6) {
        //生产商
        NSString*manufacturer=detailClass.manufacturerName;
        if (manufacturer.length==0) {
            manufacturer=@"无";}
        NSString*shengCityManufacturer=[NSString stringWithFormat:@"%@%@/%@",[ProvinceAndCity inputShengID:detailClass.supplyProvinceID],[ProvinceAndCity inputCityID: detailClass.supplyCityID],manufacturer];//省市、生产商
        return [self stringRect:shengCityManufacturer uiWidth:115 font:[UIFont systemFontOfSize:15]]+18;
    }
    if (indexPath.row==8) {
        return [self stringRect:detailClass.purchaseRemark uiWidth:115 font:[UIFont systemFontOfSize:15]]+18;
    }
    if (indexPath.row==9) {
        if (detailClass.imgPathesAry.count==0) {
            return 1;
        }
        return width/5;
    }
    if (indexPath.row==10) {
        return 108;
    }
    return 33;
}
//返回区头高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 1;
}

//返回区角高度
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    if (section==2) {
        if (detailClass.logisticsScore==nil||detailClass.serviceScore==nil||detailClass.productScore==nil) {
            return 2;
        }
        else
        {
            return 155+[detailClass.evaluationRemark boundingRectWithSize: CGSizeMake(width-30, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:14] ,NSFontAttributeName, nil] context:nil].size.height;
        }
    }
    return 2;
}

//返回每个单元格要显示的内容
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section==0) {
        //第0分区
        UITableViewCell*cell1=[[UITableViewCell alloc]init];
        cell1.selectionStyle=UITableViewCellSelectionStyleNone;
        //最左边的红色图片
        UIImageView*lrImage=[[UIImageView alloc]init];
        lrImage.image=[UIImage imageNamed:@"orangeButton_13"];
        [cell1 addSubview:lrImage];
//        [lrImage mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.offset(0); make.left.offset(0); make.width.offset(4);
//            make.bottom.offset(0);
//        }];
        
       
        
        //中标价
        UILabel*zhongBiaoL=[UILabel new];
        zhongBiaoL.text=@"中标价:";
        zhongBiaoL.font=font12;
        zhongBiaoL.frame=CGRectMake(20,8 , 50, 20);
        [cell1 addSubview:zhongBiaoL];
        //中标价价格
        UILabel*priceL=[[UILabel alloc]init];
        priceL.frame=CGRectMake(72, 8, width-175, 20);
        priceL.font=font12;
        if ([detailClass.priceUnit integerValue]==10) {
            priceL.text=[NSString stringWithFormat:@"%@元/吨",detailClass.quotePrice];
        }
        if ([detailClass.priceUnit integerValue]==20) {
            priceL.text=[NSString stringWithFormat:@"%@元/张",detailClass.quotePrice];
        }
        if([detailClass.priceUnit integerValue]==30){
            priceL.text=[NSString stringWithFormat:@"%@元/千克",detailClass.quotePrice];        }
        if ([detailClass.priceUnit integerValue]==40) {
           priceL.text=[NSString stringWithFormat:@"%@元/件",detailClass.quotePrice];
        }
        [cell1 addSubview:priceL];
        //备注
        UILabel*remarkL=[UILabel new];
        remarkL.text=@"备注:";
        remarkL.font=font12;
        remarkL.frame=CGRectMake(20, 32, 50, 20);
        [cell1 addSubview:remarkL];
        
        //显示备注信息
        UILabel*messagL=[[UILabel alloc]init];
        //messagL.frame=CGRectMake(72,32, width-175, 20);
        messagL.text=detailClass.quoteRemark;
        messagL.numberOfLines=0;
        messagL.font=font12;
        messagL.textAlignment=NSTextAlignmentLeft;
        [cell1 addSubview:messagL];
        
        if ([detailClass.isNeedTesting integerValue]==1){
            beizhuW=self.view.frame.size.width-100-70-2;
            beizhuH=[self stringRect:detailClass.quoteRemark uiWidth:beizhuW font:font12];
            CellH=[self stringRect:detailClass.quoteRemark uiWidth:beizhuW font:font12]+42;
        }else {
            beizhuW=self.view.frame.size.width-70-2;
            beizhuH=[self stringRect:detailClass.quoteRemark uiWidth:beizhuW font:font12];
            CellH=[self stringRect:detailClass.quoteRemark uiWidth:beizhuW font:font12]+42;
        }
        
         lrImage.frame=CGRectMake(0, 0, 4, CellH);
        
        messagL.frame=CGRectMake(72, 32, beizhuW, CellH-42);
        
        //图片分割线
        UIImageView*bgLineImg=[[UIImageView alloc]init];
        bgLineImg.backgroundColor=[UIColor grayColor];
        [cell1 addSubview:bgLineImg];
//        [bgLineImg mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.width.offset(0.5);  make.right.offset(-100);
//            make.top.offset(8);   make.bottom.offset(-8);
//        }];
        
        bgLineImg.frame=CGRectMake(self.view.frame.size.width-100, 8, 0.5, CellH-16);
        
        //质检状态的按钮
        UIButton*zhiJianBtn=[UIButton buttonWithType:UIButtonTypeCustom];
        zhiJianBtn.titleLabel.font=font13;
        [cell1 addSubview:zhiJianBtn];
        
//        [zhiJianBtn mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.top.offset(15);  make.left.equalTo(bgLineImg.mas_right).offset(10);  make.right.offset(-1);  make.bottom.offset(-15);
//        }];

        zhiJianBtn.frame=CGRectMake(self.view.frame.size.width-100+10, 15, 80, CellH-30);
        
        if ([detailClass.isNeedTesting integerValue]==1) {
            //判断状态进行状态兑换
            if (detailClass.reportStatus ==-1) {
                //质检取消
                [zhiJianBtn setTitle:@"质检取消" forState:UIControlStateNormal];
                [zhiJianBtn setTitleColor:[UIColor colorWithRed:195/255.0 green:195/255.0 blue:195/255.0  alpha:1] forState:UIControlStateNormal];
                [zhiJianBtn addTarget:self action:@selector(zhiJianBtn) forControlEvents:UIControlEventTouchUpInside];
            }  if(detailClass.reportStatus==0)
            {   //质检中
                [zhiJianBtn setTitle:@"质检中" forState:UIControlStateNormal];
                [zhiJianBtn setTitleColor:[UIColor colorWithRed:81/255.0 green:194/255.0 blue:220/255.0  alpha:1] forState:UIControlStateNormal];
                //zhiJianBtn.titleLabel.textColor=[UIColor colorWithRed:81/255.0 green:194/255.0 blue:220/255.0  alpha:1];
                
            }  if(detailClass.reportStatus==10)
            {
                //质检完成
                [zhiJianBtn setTitle:@"质检报告" forState:UIControlStateNormal];
                [zhiJianBtn setTitleColor:[UIColor colorWithRed:255/255.0 green:116/255.0 blue:82/255.0  alpha:1] forState:UIControlStateNormal];
                [zhiJianBtn addTarget:self action:@selector(zhiJianBtn) forControlEvents:UIControlEventTouchUpInside];
                
            }  if(detailClass.reportStatus==5)
            {
                //质检申请中
                [zhiJianBtn setTitle:@"质检申请中" forState:UIControlStateNormal];
                //zhiJianBtn.titleLabel.text=@"质检申请中";
                [zhiJianBtn setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
                //            zhiJianBtn.titleLabel.textColor=[UIColor greenColor];
                
            }
        }
        else{
            bgLineImg.hidden=YES;
            zhiJianBtn.hidden=YES;
        }
        
        return cell1;
    }
    if (indexPath.section==1) {
        //第一分区
        UITableViewCell*cell2=[[UITableViewCell alloc]init];
        cell2.selectionStyle=UITableViewCellSelectionStyleNone;
        if (indexPath.row==0) {
            //供货商信息
            UILabel*gongHuoL=[[UILabel alloc]init];
            gongHuoL.frame=CGRectMake(20, 3, 100, 19);
            gongHuoL.text=@"供货商信息";
            gongHuoL.font=[UIFont systemFontOfSize:13];
            [cell2 addSubview:gongHuoL];
            //加入黑名单按钮
            UIButton*addBlack=[UIButton buttonWithType:UIButtonTypeCustom];
            addBlack.frame=CGRectMake(width-90, 5, 85, 15);
            [addBlack setTitleColor:[UIColor colorWithRed:28.f/255.f green:52.f/255.f blue:137.f/255.f alpha:1] forState:UIControlStateNormal];
            addBlack.titleLabel.font=[UIFont systemFontOfSize:12];
            if (detailClass.isAddBlack==0) {
                [addBlack setTitle:@"加入黑名单" forState:UIControlStateNormal];
                [addBlack addTarget:self action:@selector(addBlack) forControlEvents:UIControlEventTouchUpInside];
            }
            if (detailClass.isAddBlack==1) {
                [addBlack setTitle:@"已加入黑名单" forState:UIControlStateNormal];
            }
            [cell2 addSubview:addBlack];
        }
       
        if (indexPath.row==1) {
            //头像图片
            UIImageView*headImg=[[UIImageView alloc]initWithFrame:CGRectMake(5, 15, 30, 30)];
            headImg.layer.masksToBounds=YES;
            headImg.layer.cornerRadius=15;
            [headImg sd_setImageWithURL:[NSURL URLWithString:detailClass.logoImgPath] placeholderImage:[UIImage imageNamed:@"default_head"]];
            [cell2 addSubview:headImg];
            //公司名字
            UILabel*companyName=[[UILabel alloc]init];
            companyName.text=detailClass.sellerCompanyName;
            companyName.font=font13;
            [cell2 addSubview:companyName];
            [companyName mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.offset(38);  make.height.offset(18);
                make.top.offset(8);
            }];
             //评分
            UILabel*starts=[[UILabel alloc]init];
            starts.text=[NSString stringWithFormat:@"%@分",detailClass.creditScore];
            starts.textColor=[UIColor orangeColor];
            starts.textAlignment=NSTextAlignmentRight;
            starts.font=font12;
            [cell2 addSubview:starts];
            [starts mas_makeConstraints:^(MASConstraintMaker *make) {
                make.left.equalTo(companyName.mas_right).offset(3);
                make.height.offset(16);
                make.top.offset(8);
                make.width.offset(116);
            }];
           //评分
            CWStarRateView*stars=[[CWStarRateView alloc]initWithFrame:CGRectMake(0,0, 80, 16) numberOfStars:5];
            stars.scorePercent=[detailClass.creditScore floatValue]/5;
            stars.allowIncompleteStar = YES;
            stars.hasAnimation =YES;
            [starts addSubview:stars];


            
            //交易员label标签
            UILabel*jiaoYiYuan=[[UILabel alloc]init];
            jiaoYiYuan.frame=CGRectMake(38, 34, 46, 18);
            jiaoYiYuan.text=@"交易员:";
            jiaoYiYuan.font=font12;
            [cell2 addSubview:jiaoYiYuan];
            //交易员人名
            UILabel*nameJYY=[[UILabel alloc]init];
            nameJYY.text=detailClass.sellerUserName;
            nameJYY.font=font12;
            [cell2 addSubview:nameJYY];
            [nameJYY mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(34);  make.left.equalTo(jiaoYiYuan.mas_right).offset(2);
                make.height.offset(18);  //make.width.offset(50);
            }];
            //显示交易员联系电话
//            UILabel*phoneNum=[[UILabel alloc]init];
//            phoneNum.text=detailClass.sellerMobile;
//            phoneNum.font=font12;
//            [cell2 addSubview:phoneNum];
//            [phoneNum mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.top.offset(34);  make.left.equalTo(nameJYY.mas_right).offset(2);
//                make.height.offset(18); make.width.offset(100);
//            }];
            //呼叫买家按钮
            UIButton*callSeller=[UIButton buttonWithType:UIButtonTypeCustom];
            [callSeller setTitle:@"呼叫卖家" forState:UIControlStateNormal];
            [callSeller setTitleColor:[UIColor colorWithRed:55.f/255.f green:177.f/255.f blue:249.f/255.f alpha:1] forState:UIControlStateNormal];
            callSeller.titleLabel.font=font14;
            callSeller.layer.borderColor=[UIColor colorWithRed:55.f/255.f green:177.f/255.f blue:249.f/255.f alpha:1].CGColor;
            callSeller.layer.borderWidth=1;
            callSeller.layer.masksToBounds=YES;
            callSeller.layer.cornerRadius=2;
            [callSeller addTarget:self action:@selector(callPhone) forControlEvents:UIControlEventTouchUpInside];
            [cell2 addSubview:callSeller];
//            [callSeller mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.top.offset(30);  make.height.offset(25);
//                make.width.offset(80); make.right.offset(-5);
//            }];
            
            callSeller.frame=CGRectMake(self.view.frame.size.width-85, 30, 80, 25);
            
        }
        return cell2;
    }
    
    UITableViewCell*cell3=[[UITableViewCell alloc]init];
    cell3.selectionStyle=UITableViewCellSelectionStyleNone;
    if (lv_cai==YES) {
        arrayTitle=@[@"求  购  详  情:",@"品           名:",@"牌 号/表 面:",@"规           格:",@"国           标:",@"重 量/数 量:",@"交割地/钢厂:",@"发            票:",@"备            注:",@"",@""];
    }else{
        arrayTitle=@[@"求  购  详  情:",@"品           名:",@"材 质/表 面:",@"规           格:",@"公 差 范 围:",@"重 量/数 量:",@"交割地/钢厂:",@"发            票:",@"备            注:",@"",@""];
    }
        //第0行
    UILabel*nameLabel=[[UILabel alloc]init];
    nameLabel.textColor=[UIColor colorWithRed:51.f/255.f green:51.f/255.f blue:51.f/255.f alpha:1];
    [cell3 addSubview:nameLabel];
    if (indexPath.row==0)
    {
        //求购详情label
        nameLabel.frame=CGRectMake(10, 5, 150, 25);
        nameLabel.text=arrayTitle[indexPath.row];
        nameLabel.font=font13;
        //显示时间
        UILabel*creatTime=[[UILabel alloc]init];
        creatTime.text=detailClass.createTime;
        creatTime.font=font12;
        //creatTime.backgroundColor=[UIColor blueColor];
        creatTime.frame=CGRectMake(width-145, 5, 145, 25);
        [cell3 addSubview:creatTime];
        //时钟图片
        UIImageView*imageTm=[[UIImageView alloc]init];
        imageTm.image=[UIImage imageNamed:@"ic_qiugou_time"];
        imageTm.frame=CGRectMake(width-165, 7.5, 20, 20);
        [cell3 addSubview:imageTm];
    }
    //其他行
    //商品详情
    else
    {
        nameLabel.text=arrayTitle[indexPath.row];
        nameLabel.font=font12;
        nameLabel.frame=CGRectMake(10, 12.5, 95, 16);
        //显示详细信息
        UILabel*messageL=[[UILabel alloc]initWithFrame:CGRectMake(110, 12.5, width-115, 16)];
        messageL.font=font12;
        messageL.numberOfLines=0;
        messageL.textColor=Color153;
        messageL.text=_detailArray[indexPath.row];
        [cell3 addSubview:messageL];
        //[messageL mas_makeConstraints:^(MASConstraintMaker *make) {
//            make.left.offset(120); make.top.offset(12.5); make.width.offset(width-125);
//        }];
        if (indexPath.row==6) {
            messageL.frame=CGRectMake(110, 12.5, width-115, [_detailArray[indexPath.row] boundingRectWithSize: CGSizeMake(messageL.frame.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:messageL.font ,NSFontAttributeName, nil] context:nil].size.height);
        }
        if (indexPath.row==8) {
            //计算文字高度
            messageL.frame=CGRectMake(110, 12.5, width-115, [_detailArray[indexPath.row] boundingRectWithSize: CGSizeMake(messageL.frame.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:messageL.font ,NSFontAttributeName, nil] context:nil].size.height);
            
        }
        if (indexPath.row==9) {
            for (NSInteger i=0; i<detailClass.imgPathesAry.count; i++) {
                UIImageView*imageIs=[[UIImageView alloc]initWithFrame:CGRectMake(2.5+i*(width/5-2.5), 2.5, width/5-5, width/5-5)];
                imageIs.userInteractionEnabled=YES;
                UITapGestureRecognizer*tapGesture = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(Actiondo:)];
                
                [imageIs addGestureRecognizer:tapGesture];
                [imageIs sd_setImageWithURL:[NSURL URLWithString:detailClass.imgPathesAry[i]]];
                [cell3 addSubview:imageIs];
            }
        }

        if (indexPath.row==10) {
            UIImageView*lineImg=[[UIImageView alloc]init];
            lineImg.backgroundColor=[UIColor groupTableViewBackgroundColor];
            [cell3 addSubview:lineImg];
            [lineImg mas_makeConstraints:^(MASConstraintMaker *make) {
                make.top.offset(5);   make.left.offset(0);  make.right.offset(0);
                make.height.offset(3);
            }];
            
            UIButton*touSu=[UIButton buttonWithType:UIButtonTypeCustom];
            [touSu setTitle:@"投诉" forState:UIControlStateNormal];
            [touSu setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
            touSu.titleLabel.font=font12;
            touSu.backgroundColor=[UIColor colorWithRed:229.f/255.f green:229.f/255.f blue:229.f/255.f alpha:1];
            [touSu addTarget:self action:@selector(callPhoneKefu) forControlEvents:UIControlEventTouchUpInside];
            [cell3 addSubview:touSu];
//            [touSu mas_makeConstraints:^(MASConstraintMaker *make) {
//                make.top.offset(15);   make.right.offset(-5);
//                make.height.offset(30);  make.width.offset(70);
//            }];
            touSu.frame=CGRectMake(self.view.frame.size.width-75, 15, 70, 30);
            
            
            NSArray*ary=@[@"订单编号:",@"成交时间:",@"求购账号:",@"求  购  人:"];
             NSMutableString *a = [[NSMutableString  alloc]initWithString:detailClass.orderTime];            
            NSString*str= [a substringWithRange:NSMakeRange(6, 13)];
            NSDate *d = [NSDate dateWithTimeIntervalSince1970:[str doubleValue]/1000];
            NSDateFormatter *formatter1 = [[NSDateFormatter alloc] init];
            [formatter1 setDateFormat:@"YYYY-MM-dd HH:mm"];
            NSString *showtimeNew = [formatter1 stringFromDate:d];
            NSArray*messAry=@[detailClass.orderCode,showtimeNew,detailClass.mobile,detailClass.userName];
            for (NSInteger i=0; i<4; i++) {
                //前方提示
                UILabel*detaLab=[[UILabel alloc]init];
                detaLab.font=font12;
                detaLab.textColor=Color153;
                detaLab.text=ary[i];
                detaLab.frame=CGRectMake(10, i*(18+4)+20, 80, 18);
                [cell3 addSubview:detaLab];
                //后方信息
                UILabel*mesageDetL=[[UILabel alloc]init];
                mesageDetL.frame=CGRectMake(95, i*(18+4)+20, width-180, 18);
                mesageDetL.font=font12;
                mesageDetL.textColor=Color153;
                mesageDetL.text=messAry[i];
                [cell3 addSubview:mesageDetL];
            }
        }
        
//        else{
//            messageL.frame=CGRectMake(110, 12.5, width-130, 25);
//        }
        
        
    }
    
    return cell3;
}
//返回最后一个区角的view
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    if (section==2) {
        if (detailClass.logisticsScore==nil||detailClass.serviceScore==nil||detailClass.productScore==nil) {
            return nil;
        }
        else
        {
            UITableViewHeaderFooterView*footView=[[UITableViewHeaderFooterView alloc]init];
            //最左边的红色图片
            UIImageView*lrImage=[[UIImageView alloc]initWithFrame:CGRectMake(10, 3, 3, 24)];
            lrImage.image=[UIImage imageNamed:@"orangeButton_13"];
            [footView addSubview:lrImage];
            //我的评价label
            UILabel*myEvaluation=[[UILabel alloc]init];
            myEvaluation.text=@"我的评价:";
            myEvaluation.frame=CGRectMake(15, 6, 120, 18);
            myEvaluation.font=font12;
            [footView addSubview:myEvaluation];
            NSArray*txtAr=@[@"货品与描述相符",@"卖家的服务态度",@"物流的服务质量"];
            
            NSArray*score=@[detailClass.productScore,detailClass.serviceScore,detailClass.logisticsScore];
            for (NSInteger i=0; i<3; i++) {
                UILabel*myLab=[[UILabel alloc]init];
                myLab.frame=CGRectMake(15, 33+i*32, 100, 18);
               // myLab.backgroundColor=[UIColor greenColor];
                myLab.text=txtAr[i];
                myLab.font=font12;
                myLab.textColor=[UIColor lightGrayColor];
                [footView addSubview:myLab];
                //显示评分
                CWStarRateView*stars=[[CWStarRateView alloc]initWithFrame:CGRectMake(120, 28+i*32, 150, 26) numberOfStars:5];
                stars.scorePercent=[score[i]floatValue]/5;
                stars.allowIncompleteStar = YES;
                stars.hasAnimation =YES;
                [footView addSubview:stars];
            }
            //盖在footView上防止星星被点击
            UIButton*backBtn=[UIButton buttonWithType:UIButtonTypeCustom];
            backBtn.frame=CGRectMake(0, 0, width, 120);
            backBtn.backgroundColor=[UIColor clearColor];
            [footView addSubview:backBtn];
            UILabel*scoreText=[[UILabel alloc]init];
            scoreText.font=font12;
            scoreText.textColor=Color153;
            scoreText.numberOfLines=0;
            scoreText.layer.masksToBounds=YES;
            scoreText.layer.cornerRadius=5;
            scoreText.textAlignment=NSTextAlignmentLeft;
            scoreText.layer.borderWidth=0.5;
            scoreText.layer.borderColor=[UIColor grayColor].CGColor;
            scoreText.text=detailClass.evaluationRemark;
            scoreText.frame=CGRectMake(15, 125,width-30,[detailClass.evaluationRemark boundingRectWithSize: CGSizeMake(width-30, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:scoreText.font ,NSFontAttributeName, nil] context:nil].size.height+20);
            [footView addSubview:scoreText];
            return footView;
        }
    }
    
    return nil;
}

#pragma mark---------------------------各种按钮的点击事件

-(void)zhiJianBtn
{
    if (detailClass.reportStatus==-1) {
        //质检取消
        //订单的ID号
        NSString*zhiJianID=[NSString stringWithFormat:@"%@",self.orderID];
        QuxiaoQCViewController *qcview=[[QuxiaoQCViewController alloc]init];
        qcview.orderid=zhiJianID;
        [self.navigationController pushViewController:qcview animated:YES];
        
    }else if(detailClass.reportStatus==10)
    {
        //质检完成
        //订单的ID号
        NSString*zhiJianID=[NSString stringWithFormat:@"%@",self.orderID];
        QClistViewController *qcview=[[QClistViewController alloc]init];
        qcview.orderid=zhiJianID;
        [self.navigationController pushViewController:qcview animated:YES];
        
    }
    
}

-(void)back
{
    [self.navigationController popViewControllerAnimated:YES];
}

//拨打电话
-(void)callPhone
{
    NSString*number=[NSString stringWithFormat:@"tel://%@",detailClass.sellerMobile];
    //进入打电话页面
    UIWebView *webview = [[UIWebView alloc] init];
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:number]]];
    [self.view addSubview:webview];
    //[[UIApplication sharedApplication]openURL:[NSURL URLWithString:number]];
}


//添加黑名单
-(void)addBlack
{
    if (detailClass.isAddBlack==1) {
        return;
    }

    UIAlertView*alertView=[[UIAlertView alloc]initWithTitle:@"温馨提示" message:@"你确定要将该公司加入黑名单,加入黑名单你将不再收到该公司的推送" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定",nil];
    alertView.tag=500;
    [alertView show];

}
#pragma mark------警告框的协议方法
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    if (alertView.tag==500)
    {
        if (buttonIndex==1) {
            //要加入黑名单的公司的ID
            NSDictionary*dic=@{@"SELLER_COMPANY_ID":detailClass.sellerCompanyID};
            [Controller requestWithURL:@"AppCompanyRegist/PostAddBlackList?from=app" jsondic:dic finishBlock:^(ClassData *classData) {
                NSInteger code=[classData.number integerValue];
                if (code==0)
                {
                    [detailClass setValue:@"1" forKey:@"isAddBlack"];
                    [_tableView reloadData];
                    ALERTSHOW(@"加入黑名单成功");
                }
            }];
       }
   }
}
    
    

//重新采购
-(void)again_Btn
{
    AccurateVC*accurate=[AccurateVC new];
    accurate.pageString=@"订单重新采购";
    accurate.typeString=detailClass.categoryName;
    accurate.orderDeta=detailClass;
    [self.navigationController pushViewController:accurate animated:YES];
}


//评论
-(void)comments
{
    CommentsVC*comment=[CommentsVC new];
    comment.detail=detailClass;
    [self.navigationController pushViewController:comment animated:YES];
}

//拨打客服电话
-(void)callPhoneKefu
{
    //进入打电话页面
    UIWebView *webview = [[UIWebView alloc] init];
    [webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"tel:4008850051"]]];
    [self.view addSubview:webview];

    //[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"tel://4008850051"]];
}





//计算文字高度
-(NSInteger)stringRect:(NSString*)str uiWidth:(NSInteger)widt font:(UIFont*)lfont
{
    CGRect rect = [str boundingRectWithSize:CGSizeMake(widt, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:lfont,NSFontAttributeName, nil] context:nil];
    return rect.size.height;
    //[_detailArray[indexPath.row] boundingRectWithSize: CGSizeMake(messageL.frame.size.width, CGFLOAT_MAX) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:[NSDictionary dictionaryWithObjectsAndKeys:messageL.font ,NSFontAttributeName, nil] context:nil].size.height)
}

-(void)Actiondo:(UITapGestureRecognizer *)recognizer
{
    
    
    UIImageView *tekuba_net=[recognizer view];
    
    [BigimageView showImage:tekuba_net];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
@end